package com.jumper.study.admin.service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.temporal.TemporalAdjusters;

import org.springframework.security.core.userdetails.UserDetails;

import com.jumper.study.admin.dto.req.LoginReq;
import com.jumper.study.admin.dto.resp.ChartData;
import com.jumper.study.admin.dto.resp.UserInfo;
import com.jumper.study.db.model.Account;

public interface AccountService extends BaseService<Account> {
    /**
     * 用户登录
     * @param req
     * @return
     */
    UserInfo login(LoginReq req);

    /**
     * 根据用户名读取用户
     * @param username
     * @return
     */
    UserDetails loadUserByUsername(String username);

    /**
     * 根据用户名查询用户
     * @param username
     * @return
     */
    Account getByUsername(String username);

    /**
     * 重置密码
     * @param username
     * @param password
     * @return
     */
    Boolean resetPasswordById(String username, String password);

    /**
     * 修改密码
     * @param entity
     * @param oldPassword
     * @param newPassword
     * @return
     */
    Boolean updatePasswordById(Account entity, String oldPassword, String newPassword);

    /**
     * 注册人数统计
     * @param start
     * @param end
     * @return
     */
    Long registerCount(LocalDateTime start, LocalDateTime end);

    default Long registerCount() {
        return registerCount(null, null);
    }

    /**
     * 登录人数统计
     * @param start
     * @param end
     * @return
     */
    Long loginCount(LocalDateTime start, LocalDateTime end);

    default Long loginCount(LocalDate date) {
        return loginCount(
            LocalDateTime.of(date.with(TemporalAdjusters.firstDayOfMonth()), LocalTime.of(0, 0)), 
            LocalDateTime.of(date.with(TemporalAdjusters.lastDayOfMonth()), LocalTime.of(23, 59, 59, 99999999))
        );
    }

    ChartData loginDatas(LocalDate date, int days);
}
